<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Restricted Pointers (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Restricted Pointers (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Restricted Pointers (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="C_002b_002b-Extensions.html" rel="up" title="C++ Extensions">
<link href="Vague-Linkage.html" rel="next" title="Vague Linkage">
<link href="C_002b_002b-Volatiles.html" rel="prev" title="C++ Volatiles">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
kbd.key {font-style: normal}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="Restricted-Pointers">
<div class="nav-panel">
<p>
Next: <a href="Vague-Linkage.html" accesskey="n" rel="next">Vague Linkage</a>, Previous: <a href="C_002b_002b-Volatiles.html" accesskey="p" rel="prev">When is a Volatile C++ Object Accessed?</a>, Up: <a href="C_002b_002b-Extensions.html" accesskey="u" rel="up">Extensions to the C++ Language</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Restricting-Pointer-Aliasing"><span>7.2 Restricting Pointer Aliasing<a class="copiable-link" href="#Restricting-Pointer-Aliasing"> &para;</a></span></h3>
<a class="index-entry-id" id="index-restricted-pointers"></a>
<a class="index-entry-id" id="index-restricted-references"></a>
<a class="index-entry-id" id="index-restricted-this-pointer"></a>

<p>As with the C front end, G++ understands the C99 feature of restricted pointers,
specified with the <code class="code">__restrict__</code>, or <code class="code">__restrict</code> type
qualifier.  Because you cannot compile C++ by specifying the <samp class="option">-std=c99</samp>
language flag, <code class="code">restrict</code> is not a keyword in C++.
</p>
<p>In addition to allowing restricted pointers, you can specify restricted
references, which indicate that the reference is not aliased in the local
context.
</p>
<div class="example smallexample">
<pre class="example-preformatted">void fn (int *__restrict__ rptr, int &amp;__restrict__ rref)
{
  /* <span class="r">...</span> */
}
</pre></div>

<p>In the body of <code class="code">fn</code>, <var class="var">rptr</var> points to an unaliased integer and
<var class="var">rref</var> refers to a (different) unaliased integer.
</p>
<p>You may also specify whether a member function&rsquo;s <var class="var">this</var> pointer is
unaliased by using <code class="code">__restrict__</code> as a member function qualifier.
</p>
<div class="example smallexample">
<pre class="example-preformatted">void T::fn () __restrict__
{
  /* <span class="r">...</span> */
}
</pre></div>

<p>Within the body of <code class="code">T::fn</code>, <var class="var">this</var> has the effective
definition <code class="code">T *__restrict__ const this</code>.  Notice that the
interpretation of a <code class="code">__restrict__</code> member function qualifier is
different to that of <code class="code">const</code> or <code class="code">volatile</code> qualifier, in that it
is applied to the pointer rather than the object.  This is consistent with
other compilers that implement restricted pointers.
</p>
<p>As with all outermost parameter qualifiers, <code class="code">__restrict__</code> is
ignored in function definition matching.  This means you only need to
specify <code class="code">__restrict__</code> in a function definition, rather than
in a function prototype as well.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Vague-Linkage.html">Vague Linkage</a>, Previous: <a href="C_002b_002b-Volatiles.html">When is a Volatile C++ Object Accessed?</a>, Up: <a href="C_002b_002b-Extensions.html">Extensions to the C++ Language</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
